home *** CD-ROM | disk | FTP | other *** search
- {******************************************************************}
- { }
- { OwlSpy }
- { Turbo Pascal for Windows }
- { Copyright (c) 1991 by Swan Software. All rights reserved. }
- { }
- {******************************************************************}
-
- { owlspy.pas -- A program for spying on other windows }
-
- {$R owlspy.res}
-
- program OwlSpy;
-
- uses WinTypes, WinProcs, WObjects, Strings, IDs;
-
- const
-
- infoWinWidth = 300;
- infoWinHeight = 250;
-
- type
-
- TSpyApp = object(TApplication)
- procedure InitInstance; virtual;
- procedure InitMainWindow; virtual;
- end;
-
- PTInfoWin = ^TInfoWin;
- TInfoWin = object(TWindow)
- ButtonDown: Boolean;
- HaveInfo: Boolean;
- DC: HDC;
- WindowRect: TRect;
- WindowCaption: array[0 .. 80] of Char;
- constructor Init(AParent: PWindowsObject; Origin: TPoint);
- procedure WMLButtonDown(var Msg: TMessage);
- virtual wm_First + wm_LButtonDown;
- procedure WMLButtonUp(var Msg: TMessage);
- virtual wm_First + wm_LButtonUp;
- procedure Paint(PaintDC: HDC; var PaintStruct: TPaintStruct);
- virtual;
- end;
-
- PTSpyWin = ^TSpyWin;
- TSpyWin = object(TWindow)
- ButtonDown: Boolean;
- DC: HDC;
- InfoWin: PTInfoWin;
- Lx, Ly, Gx, Gy: Word;
- constructor Init(AParent: PWindowsObject; ATitle: PChar);
- procedure GetWindowClass(var AWndClass: TWndClass); virtual;
- function GetClassName: PChar; virtual;
- procedure SetCursorInfo(X, Y: Word);
- procedure CMFileExit(var Msg: TMessage);
- virtual cm_First + cm_FileExit;
- procedure CMWindowGetInfo(var Msg: TMessage);
- virtual cm_First + cm_WindowGetInfo;
- procedure CMHelpAbout(var Msg: TMessage);
- virtual cm_First + cm_HelpAbout;
- procedure WMMouseMove(var Msg: TMessage);
- virtual wm_First + wm_MouseMove;
- procedure WMLButtonDown(var Msg: TMessage);
- virtual wm_First + wm_LButtonDown;
- procedure WMLButtonUp(var Msg: TMessage);
- virtual wm_First + wm_LButtonUp;
- procedure Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
- virtual;
- end;
-
-
- { TSpyApp }
-
-
- { Initialize this program instance }
-
- procedure TSpyApp.InitInstance;
- begin
- TApplication.InitInstance;
- HAccTable := LoadAccelerators(HInstance, PChar(id_Acc));
- end;
-
-
- { Initialize TSpyApp's main window }
-
- procedure TSpyApp.InitMainWindow;
- begin
- MainWindow := New(PTSpyWin, Init(nil, 'OWL Spy Utility'));
- end;
-
-
-
- { TInfoWin }
-
- { Construct instance of TInfoWin object }
-
- constructor TInfoWin.Init(AParent: PWindowsObject; Origin: TPoint);
- begin
- TWindow.Init(AParent, 'Window Information');
- with Attr do
- begin
- Style := ws_PopUp or ws_OverlappedWindow or ws_Visible;
- X := Origin.X;
- Y := Origin.Y;
- W := infoWinWidth;
- H := infoWinHeight;
- end;
- ButtonDown := false;
- HaveInfo := false;
- end;
-
-
- { Respond to left-mouse-button-down event }
-
- procedure TInfoWin.WMLButtonDown(var Msg: TMessage);
- begin
- if not ButtonDown then
- begin
- ButtonDown := true;
- SetCapture(HWindow);
- DC := GetDC(HWindow);
- SetCursor(LoadCursor(0, idc_UpArrow));
- HaveInfo := false;
- end;
- end;
-
-
- { Respond to release of left mouse button }
-
- procedure TInfoWin.WMLButtonUp(var Msg: TMessage);
- var
- P: TPoint; { Cursor location }
- HW: HWnd; { Handle to window under cursor }
- begin
- if ButtonDown then
- begin
- ReleaseCapture;
- ReleaseDC(HWindow, DC);
- ButtonDown := false;
- GetCursorPos(P);
- HW := WindowFromPoint(P);
- GetWindowText(HW, WindowCaption, Sizeof(WindowCaption) - 1);
- GetWindowRect(HW, WindowRect);
- HaveInfo := true;
- InvalidateRect(HWindow, nil, true);
- UpdateWindow(HWindow);
- SetCursor(LoadCursor(0, idc_Arrow));
- end;
- end;
-
-
- { Display information in the information window }
-
- procedure TInfoWin.Paint(PaintDC: HDC; var PaintStruct: TPaintStruct);
- var
- S: array[0 .. 20] of Char;
- begin
- TWindow.Paint(PaintDC, PaintStruct);
- if HaveInfo then
- begin
- TextOut(PaintDC, 10, 10, WindowCaption, StrLen(WindowCaption));
- with WindowRect do
- begin
- WVSPrintf(S, 'Top = %5d ', Top);
- TextOut(PaintDC, 10, 40, S, StrLen(S));
- WVSPrintf(S, 'Left = %5d ', Left);
- TextOut(PaintDC, 10, 70, S, StrLen(S));
- WVSPrintf(S, 'Right = %5d ', Right);
- TextOut(PaintDC, 10, 100, S, StrLen(S));
- WVSPrintf(S, 'Bottom = %5d ', Bottom);
- TextOut(PaintDC, 10, 130, S, StrLen(S));
- end;
- end;
- end;
-
-
- { TSpyWin }
-
-
- { Construct a TSpyWin object }
-
- constructor TSpyWin.Init(AParent: PWindowsObject; ATitle: PChar);
- begin
- TWindow.Init(AParent, ATitle);
- with Attr do
- begin
- Menu := LoadMenu(HInstance, PChar(id_Menu));
- X := GetSystemMetrics(sm_CXScreen) div 8;
- Y := GetSystemMetrics(sm_CYScreen) div 8;
- H := Y * 6;
- W := X * 6;
- end;
- InfoWin := nil;
- ButtonDown := false;
- SetCursorInfo(0, 0);
- end;
-
-
- { Return window "class" information }
-
- procedure TSpyWin.GetWindowClass(var AWndClass: TWndClass);
- begin
- TWindow.GetWindowClass(AWndClass);
- AWndClass.HIcon := LoadIcon(HInstance, PChar(id_Icon));
- end;
-
-
- { Return window "class" name }
-
- function TSpyWin.GetClassName: PChar;
- begin
- GetClassName := 'TSpyWin';
- end;
-
-
- { Initialize cursor location variables }
-
- procedure TSpyWin.SetCursorInfo(X, Y: Word);
- var
- P: TPoint;
- begin
- GetCursorPos(P);
- Lx := X;
- Ly := Y;
- Gx := P.X;
- Gy := P.Y;
- end;
-
-
- { Execute the File menu's Exit command }
-
- procedure TSpyWin.CMFileExit(var Msg: TMessage);
- begin
- CloseWindow;
- end;
-
-
- { Execute Window:Get info... command }
-
- procedure TSpyWin.CMWindowGetInfo(var Msg: TMessage);
- const
- instructions =
- 'Click and hold the left mouse button inside'#13+
- 'the "Window Information" window. Move the mouse'#13+
- 'pointer to any window, and release. You may close'#13+
- 'this dialog or leave it open.';
- var
- P: TPoint;
- R: TRect;
- begin
- if (InfoWin = nil) or (not IsWindow(InfoWin^.HWindow)) then
- begin
- GetClientRect(HWindow, R);
- P.X := R.Right - infoWinWidth;
- P.Y := R.Top;
- ClientToScreen(HWindow, P);
- InfoWin := PTInfoWin(Application^.MakeWindow(New(PTInfoWin, Init(@Self, P))));
- MessageBox(HWindow, instructions, 'Instructions', mb_Ok);
- end else
- SetFocus(InfoWin^.HWindow);
- end;
-
-
- { Execute the Help menu's About OwlSpy command }
-
- procedure TSpyWin.CMHelpAbout(var Msg: TMessage);
- var
- Dialog: TDialog;
- begin
- Dialog.Init(@Self, PChar(id_About));
- Dialog.Execute;
- Dialog.Done;
- end;
-
-
- { Respond to mouse movement events }
-
- procedure TSpyWin.WMMouseMove(var Msg: TMessage);
- begin
- SetCursorInfo(Msg.LParamLo, Msg.LParamHi);
- InvalidateRect(HWindow, nil, false);
- end;
-
-
- { Capture mouse upon receiving left-mouse-button-down event }
-
- procedure TSpyWin.WMLButtonDown(var Msg: TMessage);
- begin
- if not ButtonDown then
- begin
- ButtonDown := true;
- SetCapture(HWindow);
- DC := GetDC(HWindow);
- SetCursor(LoadCursor(0, idc_Cross));
- end;
- end;
-
-
- { Release mouse upon receiving left-mouse-button-up event }
-
- procedure TSpyWin.WMLButtonUp(var Msg: TMessage);
- begin
- if ButtonDown then
- begin
- ReleaseCapture;
- ReleaseDC(HWindow, DC);
- ButtonDown := false;
- SetCursor(LoadCursor(0, idc_Arrow));
- end;
- end;
-
-
- { Display information in program's main window }
-
- procedure TSpyWin.Paint(PaintDC: HDC; var PaintInfo: TPaintStruct);
- var
- S: array[0 .. 20] of Char;
- begin
- TWindow.Paint(PaintDC, PaintInfo);
- WVSPrintf(S, 'Local X = %5d ', Lx);
- TextOut(PaintDC, 10, 10, S, StrLen(S));
- WVSPrintf(S, 'Local Y = %5d ', Ly);
- TextOut(PaintDC, 10, 40, S, StrLen(S));
- WVSPrintf(S, 'Global X = %5d ', Gx);
- TextOut(PaintDC, 10, 70, S, StrLen(S));
- WVSPrintf(S, 'Global Y = %5d ', Gy);
- TextOut(PaintDC, 10, 100, S, StrLen(S));
- end;
-
-
- var
-
- SpyApp: TSpyApp;
-
-
- begin
- SpyApp.Init('OwlSpy');
- SpyApp.Run;
- SpyApp.Done;
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 8/28/1991
- ---------------------------------------------------------------}
-